package dnl.toolbox.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import de.schlichtherle.io.File;

public class FileSystemResource implements Resource {

	private File file;

	public FileSystemResource(File file) {
		super();
		this.file = file;
	}

	public FileSystemResource(java.io.File file) {
		super();
		this.file = new File(file);
	}

	@Override
	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	@Override
	public InputStream getInputStream() throws IOException {
		if (file != null && de.schlichtherle.io.File.class.isInstance(file)){
			return new de.schlichtherle.io.FileInputStream(file);
		}
		return new FileInputStream(file);
	}

	@Override
	public OutputStream getOutputStream() throws IOException {
		return new FileOutputStream(file);
	}

	@Override
	public boolean exists() {
		return file.exists();
	}
}
